package org.example.btchat.server;

import java.io.IOException;

import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;

public class AcceptThread extends Thread
{
	private BluetoothServerSocket server;
	private ServerService service;
	
	public AcceptThread(BluetoothServerSocket server, ServerService service)
	{
		this.server = server;
		this.service  = service;
	}
	
	@Override
	public void run()
	{
		while(true)
		{
			BluetoothSocket socket;
			try
			{
				socket = server.accept();
			}
			catch(IOException e)
			{
				continue;
			}
			
			addSocket(socket);
		}
	}
	
	private void addSocket(BluetoothSocket socket)
	{
		service.onSocketConnected(socket);
	}
}
